home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / tool / tetujin / src / g_eff / triflt.c < prev    next >
Text File  |  1994-11-16  |  2KB  |  142 lines

  1. /*
  2.         graphic effect lib.
  3.           test Filter
  4.  
  5.         h. Toda 1994 6 3
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <egb.h>
  11. #include "g_eff.h"
  12.  
  13. #define NOERR 0        /* no error */
  14.  
  15. static int mx ;
  16. static int aSen ;
  17. static int mSen ;
  18. static int cMax ;
  19. static int aMax ;
  20. static int x1 ;
  21. static int y1 ;
  22. static int x2 ;
  23. static int y2 ;
  24. static int (*read1)() ;
  25. static int (*write)() ;
  26. static int (*mask)() ;
  27.  
  28. g_3hFilter( BASICPARA *para )
  29. {
  30.     unsigned char a[4][4] ;
  31.     int i, x, y ;
  32.     int n ;
  33.  
  34.     mx = para->mix ;
  35.     aSen = para->alphaSen ;
  36.     mSen = para->maskSen ;
  37.     cMax = para->colorMax ;
  38.     aMax = para->alphaMax ;
  39.     x1 = para->lupx ;
  40.     y1 = para->lupy ;
  41.     x2 = para->rdwx ;
  42.     y2 = para->rdwy ;
  43.     read1 = para->read1 ;
  44.     write = para->write ;
  45.     mask = para->mask ;
  46.  
  47.     for( y = y1 ; y <= y2 ; y++ )
  48.     {
  49.         for( x=x1 ; x <= x2 ; x++ )
  50.         {
  51.             read1( x-1, y,   a[0] ) ;
  52.             read1( x,   y,   a[1] ) ;
  53.             read1( x+1, y,   a[2] ) ;
  54.  
  55.             for( i=0 ; i<3 ; i++ )
  56.             {
  57.                 n = ck3(
  58.                          a[0][i], a[1][i], a[2][i]
  59.                        ) ;
  60.                 a[3][i] = a[n][i] ;
  61.             }
  62.             mixWrite( x, y, a[3], a[1] ) ;
  63.         }
  64.     }
  65.  
  66.     return NOERR ;
  67. }
  68.  
  69. static mixWrite( int x, int y, unsigned char *a, unsigned char *b )
  70. {
  71.     unsigned char c[4] ;
  72.     int mix ;
  73.  
  74.     if( mSen )
  75.     {
  76.         if( mask( x, y ) >= mSen )
  77.             return NOERR ;
  78.     }
  79.  
  80.     mix = mx ;
  81.     if( aSen )
  82.     {
  83.         mix = mix * b[3] / aMax ;
  84.     }
  85.  
  86.     c[0] = ( a[0] * mix + b[0] * ( 256 - mix ) + 0x80 ) >> 8 ;
  87.     c[1] = ( a[1] * mix + b[1] * ( 256 - mix ) + 0x80 ) >> 8 ;
  88.     c[2] = ( a[2] * mix + b[2] * ( 256 - mix ) + 0x80 ) >> 8 ;
  89.     c[3] = b[3] ;
  90.  
  91.     if( mix )
  92.     {
  93.         write( x, y, c ) ;
  94.     }
  95.  
  96.     return NOERR ;
  97. }
  98.  
  99. static ck3( int a, int b, int c )
  100. {
  101.     int temp ;
  102.     int n0, n1, n2 ;
  103.  
  104.     n0 = 0 ; n1 = 1 ; n2 = 2 ;
  105.  
  106.     if( a > b )
  107.     {
  108.         temp = a ;
  109.         a = b ;
  110.         b = temp ;
  111.  
  112.         temp = n0 ;
  113.         n0 = n1 ;
  114.         n1 = temp ;
  115.     }
  116.  
  117.     if( a > c )
  118.     {
  119.         temp = a ;
  120.         a = c ;
  121.         c = temp ;
  122.  
  123.         temp = n0 ;
  124.         n0 = n2 ;
  125.         n2 = temp ;
  126.     }
  127.  
  128.     if( b > c )
  129.     {
  130.         temp = b ;
  131.         b = c ;
  132.         c = temp ;
  133.  
  134.         temp = n1 ;
  135.         n1 = n2 ;
  136.         n2 = temp ;
  137.     }
  138.  
  139.     return n1 ;
  140. }
  141.  
  142.